/*************************************************************************
    > File Name: 
    > Author: Lancer
    > Mail: 18826075768@163.com
************************************************************************/

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctime>

using namespace std;

typedef void(*Callback)(void*);

void settimer(unsigned int id, int msec, Callback cb){
    if(msec < 0){
        return;
    }

    clock_t start, finish;
    start = clock();
    double total = 0.0;
    while(1){
        finish = clock();
        total = (double)(finish - start) / CLOCKS_PER_SEC * 1000;
        if(total > msec){
            cb(&total);
            break;
        }
    }
}

void callback(void* args){
    cout << "go to timer1: " << *(double*)args << endl;
}

int main(){
    while(1){
        settimer(1, 2000, callback);
    }
    return 0;
}